#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int getScore(const string &report)
    {
        int ret = 0;
        regex reg(" ");
        sregex_token_iterator pos(report.begin(), report.end(), reg, -1);
        decltype(pos) end;
        for (; pos != end; pos++)
        {
            if (positive.count(pos->str()))
            {
                ret += 3;
            }
            else if (negative.count(pos->str()))
            {
                ret -= 1;
            }
        }
        return ret;
    }
    vector<int> topStudents(vector<string> &positive_feedback, vector<string> &negative_feedback,
                            vector<string> &report, vector<int> &student_id, int k)
    {
        unordered_map<int, int> m;
        vector<int> ret;
        for (auto e : positive_feedback)
        {
            positive.insert(e);
        }
        for (auto e : negative_feedback)
        {
            negative.insert(e);
        }
        for (int i = 0; i < student_id.size(); i++)
        {
            int score = getScore(report[i]);
            m[student_id[i]] += score;
        }
        auto com = [](const pair<int, int> &lhs, const pair<int, int> &rhs)
        {
            return lhs.second == rhs.second ? lhs.first < rhs.first : lhs.second > rhs.second;
        };
        vector<pair<int, int>> tmp;
        for (auto e : m)
        {
            tmp.push_back(e);
        }
        sort(tmp.begin(), tmp.end(), com);
        for (int i = 0; i < k; ++i)
        {
            ret.push_back(tmp[i].first);
        }
        return ret;
    }
    unordered_set<string> positive;
    unordered_set<string> negative;
};